﻿

namespace LxCFD
{
    public class GeomAverageMonitor : AverageMonitorBase
    {
        public override void CalCellValue(FvZone selectedZone,double[] array, int taskIndex)
        {
            double sum = 0, weight = 0;
            var cells = selectedZone.Cells;
            selectedZone.InnerIndex.CellIDs.GetSeg(out int i1, out int endp1, taskIndex);
            for (; i1 < endp1; i1++)
            {
                ref FvCell cell = ref cells[i1];
                sum += array[i1] * cell.Volumn;
                weight += cell.Volumn;
            }
            ThreadsMath.AddToSum(sum, weight);
        }
        public override void CalFaceValue(FvZone selectedZone, FvThread selectedThread, double[] array, int taskIndex)
        {
            double sum = 0, weight = 0;
            var faces = selectedZone.Faces;
            selectedThread.ThreadIndex.FaceIDs.GetSeg(out int i1, out int endp1, taskIndex);
            for (; i1 < endp1; i1++)
            {
                ref FvFace face = ref faces[i1];
                sum += array[face.NSideCell] * face.Area;
                weight += face.Area;
            }
            ThreadsMath.AddToSum(sum, weight);
        }
    }
}

